/*
 *  AbstractRegionTester.cpp
 *  SoundController0002
 *
 *  Created by jiro on 11/10/05.
 *  Copyright 2011 jiro music. All rights reserved.
 *
 */

#include "AbstractRegionTester.h"
#include "../../../sc/Tester/CustomAssert.h"
#include "../System0039.h"
#include "../AbstractLine.h"
#include "../AbstractRegion.h"

namespace sc
{
namespace system0039
{

	void AbstractRegionTester::TestAll()
	{
		Test_GetConcreteRegion000();
		Test_GetConcreteRegion001();
		Test_GetConcreteRegion002();
	}

	void AbstractRegionTester::Test_GetConcreteRegion000()
	{
		AbstractRegion region;
		AbstractLine line;

		line.AddNote( AbstractNote( Note::D1, Note::E2, Note::mezzoPiano ) );
		region.AddLine( line );

		ConcreteLine concreteLine;
		ConcreteRegion concreteRegion;
		ConcreteNote concreteNote;

		AssertEqual( region.GetConcreteRegionCount(), 2 );
		region.GetConcreteRegion( 0, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 1 );

		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 1 );

		concreteNote = concreteLine[ 0 ];

		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::E2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 2, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 1, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 1 );

		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 1 );

		concreteNote = concreteLine[ 0 ];

		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::E2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteRegion.clear();
	}

	void AbstractRegionTester::Test_GetConcreteRegion001()
	{
		AbstractRegion region;
		AbstractLine line;

		line.AddNote( AbstractNote( Note::D1, Note::B2, Note::mezzoPiano ) );
		line.AddNote( AbstractNote( Note::D1, Note::D3, Note::mezzoPiano ) );
		region.AddLine( line );

		ConcreteLine concreteLine;
		ConcreteRegion concreteRegion;
		ConcreteNote concreteNote;

		AssertEqual( region.GetConcreteRegionCount(), 4 );

		region.GetConcreteRegion( 0, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 1 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 2 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteNote = concreteLine[ 1 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 1, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 1 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 2 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteNote = concreteLine[ 1 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 5, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 2, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 1 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 2 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 4, Note::mezzoPiano ) );
		concreteNote = concreteLine[ 1 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 3, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 1 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 2 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 4, Note::mezzoPiano ) );
		concreteNote = concreteLine[ 1 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 5, Note::mezzoPiano ) );
		concreteRegion.clear();

	}

	void AbstractRegionTester::Test_GetConcreteRegion002()
	{
		AbstractRegion region;
		AbstractLine line;

		line.AddNote( AbstractNote( Note::D1, Note::B2, Note::mezzoPiano ) );
		region.AddLine( line );
		
		line.Clear();
		line.AddNote( AbstractNote( Note::D1, Note::D3, Note::mezzoPiano ) );
		region.AddLine( line );

		ConcreteLine concreteLine;
		ConcreteRegion concreteRegion;
		ConcreteNote concreteNote;

		AssertEqual( region.GetConcreteRegionCount(), 4 );

		region.GetConcreteRegion( 0, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 2 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );

		concreteLine = concreteRegion[ 1 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 1, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 2 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );

		concreteLine = concreteRegion[ 1 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 5, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 2, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 2 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												   ::sc::hs::Sound::SingleSineWave, Note::D1, 4, Note::mezzoPiano ) );

		concreteLine = concreteRegion[ 1 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 3, Note::mezzoPiano ) );
		concreteRegion.clear();

		region.GetConcreteRegion( 3, AbstractRegion::LeftAlignment, concreteRegion );
		AssertEqual( concreteRegion.size(), 2 );
		concreteLine = concreteRegion[ 0 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::B2, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 4, Note::mezzoPiano ) );

		concreteLine = concreteRegion[ 1 ];
		AssertEqual( concreteLine.size(), 1 );
		concreteNote = concreteLine[ 0 ];
		AssertTrue( concreteNote == ConcreteNote( ::sc::hs::Sound::SingleSineWave, Note::D3, 1, Note::mezzoPiano, 
												  ::sc::hs::Sound::SingleSineWave, Note::D1, 5, Note::mezzoPiano ) );
		concreteRegion.clear();

	}

}
}